<h1><?php echo lang('text_heading_title_territory') ?></h1>

<?php if (get_instance()->session->flashdata('message')) { ?>
<div class="alert alert-block fade in">
	<button class="close" type="button" data-dismiss="alert"> x </button>
	<?php echo get_instance()->session->flashdata('message') ?>
</div>
<?php } ?>

<table id="territory"></table>

<script src="<?php echo base_url('/assets/js/jquery-1.7.1.js') ?>"></script>
<script src="<?php echo base_url('/assets/js/easyui/jquery.easyui.min.js') ?>"></script>
<link href="<?php echo base_url('/assets/js/easyui/themes/default/easyui.css') ?>" rel="stylesheet" />
<link href="<?php echo base_url('/assets/js/easyui/themes/icon.css') ?>" rel="stylesheet" />

<style>

<?php foreach ($territory_type as $type) { ?>
.icon-territory-<?php echo $type['territory_type_id'] ?> {
	background: url('<?php echo base_url('/themes/'.$this->config('theme').'/img/territory_icon/'.$type['territory_type_icon']) ?>') no-repeat 0px 0px;
}
<?php } ?>

</style>

<script><!--
$(function() {

	$('#territory').treegrid({
		title:'Territory Tree',
		width: '100%',
		height: 650,
		nowrap: false,
		rownumbers: true,
		animate: true,
		url: '<?php echo base_url('/territory') ?>', //'http://localhost/smartfren_sts_rc_018/index.php/territory/territory_json',
		method: 'get',
		queryParams: { cmd: 'GET_TERRITORY' },
		idField: 'id',
		treeField: 'name',
		columns:[[
			{ field: 'name', title: '<?php echo lang('text_table_territory_name') ?>', width: 700 },
			{ field: 'size', title:'<?php echo lang('text_table_territory_maintained_by') ?>', width: 300 },
			{ field: 'date', title: '<?php echo lang('text_table_territory_action') ?>', width: 200 }
		]],
		onBeforeLoad:function(row,param){
			if (row){
				$(this).treegrid('options').url = '<?php echo base_url('/territory/index') ?>/'+row.ter_id+'/'+row.tipe+'?cmd=GET_TERRITORY';
				
				//$(this).treegrid('options').url = 'http://localhost/smartfren_sts_rc_018/index.php/territory/territory_json/'+row.ter_id+'/'+row.tipe;
			} 
		}
	});
});

//--></script>

<script><!--
var deleterow = function(index, ter_id, jml) {
	if (jml == 0) {
		if (confirm('Are you sure you wan to delete?')) {
			$.ajax({
				url: '<?php echo base_url('/territory') ?>',
				type: 'GET',
				data: { cmd: 'DELETE', ter_id:ter_id },
				dataType: 'json',
				success: function(json) {
					if (json['status'] == 'OK') {
						setTimeout("location.reload(true);", 100);
					}
				}
			});
		}
	} else {
		alert('You cannot delete this data, because data have a node');
	}
};
//--></script>